<template>
   <RouterLink to="/AddInvestInfo" style="margin-right:10px;">添加投资</RouterLink>
   <RouterLink to="/AddFinanInfo" style="margin-right:10px;">添加理财</RouterLink>
   <RouterLink to="/ShowFinanInfo" style="margin-right:10px;">显示理财</RouterLink>
   <RouterLink to="/AddBorow" style="margin-right:10px;">添加借款</RouterLink>
   <RouterLink to="/ShowBorow" style="margin-right:10px;">显示借款</RouterLink>


   <h2>投资项目列表</h2>
    <InvestInfoContent v-slot="itme">
        <a href="#" @click="DeleteInfo(itme.id)" style="margin-right: 10px;">删除</a>
        <a href="#" @click="EditInfo(itme.id)">修改</a>
    </InvestInfoContent>
</template>

<script setup lang="ts">
import InvestInfoContent from './InvestInfoContent.vue';
import 'bootstrap/dist/css/bootstrap.min.css'


//引入axios
import axios from 'axios';
//
import { useRouter } from 'vue-router';

//创建路由操作对象
const router = useRouter();
//删除投资信息
const DeleteInfo = (I_Id: number) => {
    if (confirm("确定要删除吗？")) {
        axios.delete("https://localhost:44387/api/Invests/DeleteInvestInfo", {
            params: {
                I_Id: I_Id
            }
        })
            .then(res => {
                //处理响应数据
                console.log(res.data);
                if (res.data > 0) {
                    alert("投资信息删除成功");
                }
                else if (res.data == -1) {
                    alert("有人投资，无法删除");
                }
                else {
                    alert("投资信息删除失败");
                }

                //刷新页面
                window.location.reload();
            })
            .catch(error => {
                //处理错误
                console.log(error);
            })
    }
}
//通过路由跳转到修改页面
const EditInfo = (I_Id: number) => {
    router.push({
        path: '/EditInvestInfo',
        query: {
            I_Id: I_Id
        }
    })
}

</script>
